<template>
  <div>
    <h3>爷爷传过来的数据：{{ msg }}</h3>
    <p>{{ msg2 }}</p>
  </div>
</template>

<!-- <script>
export default {
  name: 'SunChild',
  // inject: ['grandpaMsg']
  /*   inject: {
    // 起别名
    msg: 'grandpaMsg'
  } */
  inject: {
    // 起别名
    msg: {
      from: 'grandpaMsg',
      default: '默认值'
    }
  }
}
</script> -->
<script setup>
import { inject } from 'vue'
// 直接注入
const msg = inject('grandpaMsg', '默认值')
const msg2 = inject('gMsg')
</script>
